***********--------------------------------------------
** MODERNISATION

sum e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_Vanhanen_nonag_ipo ///
v2peprisch v2pesecsch v2petersch e_miferrat e_pelifeex

sum e_Vanhanen_literate_ipo e_miurbani e_Vanhanen_nonag_ipo e_miferrat e_peinfmor   e_pelifeex  v2peprisch v2pesecsch v2petersch 


sum e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_Vanhanen_nonag_ipo ///
v2peprisch v2pesecsch v2petersch e_miferrat e_pelifeex if country==278


// Literate population (%), (E) (e_Vanhanen_literate_ipo)
tab year if e_Vanhanen_literate_ipo!=.
tab country if e_Vanhanen_literate_ipo!=.
sum e_Vanhanen_literate_ipo 

//Urbanization (E) (e_miurbani)
tab year if e_miurbani!=.
tab country if e_miurbani!=.
sum e_miurbani 

//Infant mortality rate (E)(e_peinfmor)
tab year if e_peinfmor!=.
tab country if e_peinfmor!=.
sum e_peinfmor 

//Life expectancy (E) (e_pelifeex)
tab year if e_pelifeex!=.
tab country if e_pelifeex!=.
sum e_pelifeex 

//Non-agricultural population % (E) (e_Vanhanen_nonag_ipo) 
tab year if e_Vanhanen_nonag_ipo!=.
tab country if e_Vanhanen_nonag_ipo!=.
sum e_Vanhanen_nonag_ipo 

// Fertility rate
tab year if e_miferrat!=.
tab country if e_miferrat!=.
sum e_miferrat

// School education
sum v2peprisch v2pesecsch v2petersch

//Primary school enrollment (A)(v2peprisch)
tab year if v2peprisch!=.
tab country if v2peprisch!=.

//Secondaryschoolenrollment(A)(v2pesecsch)
tab year if v2pesecsch!=.
tab country if v2pesecsch!=.

//Secondary tertiary enrollment (A) (v2petersch)
tab year if v2petersch!=.
tab country if v2petersch!=.

corr e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_Vanhanen_nonag_ipo ///
v2peprisch v2pesecsch v2petersch e_miferrat

sum e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_Vanhanen_nonag_ipo ///
v2peprisch v2pesecsch v2petersch e_miferrat


//linear interploation

browse country year e_Vanhanen_literate_ipo


foreach var of varlist e_Vanhanen_literate_ipo e_miurbani e_Vanhanen_nonag_ipo e_miferrat e_peinfmor   e_pelifeex  v2peprisch v2pesecsch v2petersch {

bys country: ipolate `var' year, gen(`var'_int)
drop `var'
rename `var'_int `var'
}

sum e_Vanhanen_literate_ipo e_miurbani e_Vanhanen_nonag_ipo e_miferrat e_peinfmor   e_pelifeex  v2peprisch v2pesecsch v2petersch

sort country year
browse country year e_Vanhanen_literate_ipo 


// Count valid measures country-year

foreach var of varlist e_Vanhanen_literate_ipo e_miurbani e_Vanhanen_nonag_ipo e_miferrat e_peinfmor   e_pelifeex  v2peprisch v2pesecsch v2petersch {
gen `var'1 =1 if `var'!=.
replace `var'1=0 if `var'==.
}

capture drop modern_w
gen modern_w = (e_Vanhanen_literate_ipo1+ e_miurbani1+ e_Vanhanen_nonag_ipo1+ e_miferrat1+ e_peinfmor1+ e_pelifeex1+ v2peprisch1+ v2pesecsch1+ v2petersch1)/9

gen modern_N = (e_Vanhanen_literate_ipo1+ e_miurbani1+ e_Vanhanen_nonag_ipo1+ e_miferrat1+ e_peinfmor1+ e_pelifeex1+ v2peprisch1+ v2pesecsch1+ v2petersch1)

drop e_Vanhanen_literate_ipo1 e_miurbani1 e_Vanhanen_nonag_ipo1 e_miferrat1 e_peinfmor1 e_pelifeex1 v2peprisch1 v2pesecsch1 v2petersch1

tab modern_w if year>1920
tab modern_N if  country_name =="United States of America"

**** FACTOR ANALYSIS OF MODERNIZATION
pca e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_miferrat e_Vanhanen_nonag_ipo v2peprisch v2pesecsch v2petersch , mineig(1)
predict educ_factor


*** Standardizing media variable to 0-1
sum educ_factor,d

gen educ_factora = educ_factor - r(min)
sum educ_factora,d

gen modernization = educ_factora/r(max)
sum modernization,d
drop  educ_factora

lab var modernization "Modernization: Standardized Factor score[0-1]"
gen modern_all =  modernization

sum modern_all

*browse e_Vanhanen_literate_ipo e_miurbani e_peinfmor e_pelifeex e_Vanhanen_nonag_ipo v2peprisch v2pesecsch v2petersch if educ_factor==.

do "Data/DoFiles/MissingFactor_Modernization"

egen missing_modern = rmean(educ_factor1d-educ_factor119d)
replace modernization = missing_modern if modernization==.

drop educ_factor1d-educ_factor119d

tab year if modernization!=.
tab country if modernization!=.

sort country year 
browse country year  modernization  modern_w

pwcorr modernization  modern_all e_pelifeex e_miferrat e_miurbani
sum modernization  modern_all e_pelifeex e_miferrat e_miurbani
